package com.example.goodsprovider.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.myshop.b2b.commonmodule.Cart;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @author likaiping
* @description 针对表【cart】的数据库操作Mapper
* @createDate 2024-07-03 15:07:29
* @Entity com.example.goodsprovider.pojo.Cart
*/
public interface CartMapper extends BaseMapper<Cart> {
    /**
     * 根据ID删除购物车
     * @param gid
     * @return
     */
    @Delete("delete from cart WHERE id = #{gid}")
    int deleteCart(@Param("gid") int gid);

    /**
     * 根据ID查询购物车商品数量
     * @param id
     * @return
     */
    @Select("select number from cart WHERE id = #{id}")
    Integer selectNumberById(@Param("id") int id);

    /**
     * 根据ID查询购物车
     * @param id
     * @return
     */
    @Select("select * from cart WHERE id = #{id}")
    Cart selectAllById(@Param("id") int id);

    /**
     * 购买商品后添加一条订单数据
     * @param goodsname
     * @param number
     * @param price
     * @param uid
     * @return
     */
    @Insert("INSERT INTO userorder (goodsname, number, price,time,uid ) VALUES(#{goodsname}, #{number}, #{price},now(),#{uid});")
    int insertOrder(@Param("goodsname") String goodsname,
                    @Param("number")int number,
                    @Param("price")int price,
                    @Param("uid")int uid);

    /**
     * 查询所有购物车
     * @param uid
     * @return
     */
    @Select("select * from cart WHERE uid = #{uid}")
    List<Cart> getAllcart(@Param(value = "uid")int uid);

    /**
     * 插入一条购物车
     * @param goodsname
     * @param number
     * @param price
     * @param goodid
     * @param uid
     * @return
     */
    @Insert("INSERT INTO cart ( goodsname,number, price,goodid,uid) VALUES(#{goodsname}, #{number}, #{price},#{goodid},#{uid});")
    int intcart(@Param(value = "goodsname")String goodsname, @Param(value
            ="number")int number, @Param(value = "price")int price, @Param(value
            ="goodid")int goodid, @Param(value = "uid")int uid);

    /**
     * 修改购物车商品数量
     * @param number
     * @param id
     * @return
     */
    @Update("UPDATE cart SET number = number+#{number} WHERE id = #{id} ;")
    int updateCart(@Param("number") int number,@Param("id")
    int id);

    /**
     * 单次修改购物车商品数量
     * @param number
     * @param id
     * @return
     */
    @Update("UPDATE cart SET number = #{number} WHERE id = #{id} ;")
    boolean updateCartNumber(@Param("number") int number,@Param("id") int id);
}




